package ch.uzh.ifi.sopra.gruppe9.game.junit;
import ch.uzh.ifi.sopra.gruppe9.text_pdk.*;

import junit.framework.*;
import static org.junit.Assert.*;
import java.rmi.RemoteException;
import java.util.ArrayList;

import org.junit.BeforeClass;
import org.junit.Test;


public class PlayerTest extends TestCase {

	private IGameBoard myBoard;
	private IPlayer TestPlayer;
	private ArrayList<BuyingAgent> buyingAgents = new ArrayList<BuyingAgent>();
	private ArrayList<Tower> towers = new ArrayList<Tower>();
	
	public void testcheckMoney() throws RemoteException{
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		assertTrue(TestPlayer.checkMoney(0));
		assertFalse(TestPlayer.checkMoney(2));
	}
	
	public void testrecieveMoney() throws RemoteException {
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		assertTrue(TestPlayer.checkMoney(0));
		TestPlayer.recieveMoney(5);
		assertTrue(TestPlayer.checkMoney(5));
		assertFalse(TestPlayer.checkMoney(6));
	}
	
	public void testaddPoints() throws RemoteException {
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		TestPlayer.addPoints(5);
		assertEquals(5, TestPlayer.getPoints());
		TestPlayer.addPoints(-6);
		assertEquals(-1, TestPlayer.getPoints());
	}
	
	public void testsetReady() throws RemoteException {
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		TestPlayer.setReady(true);
		assertTrue(TestPlayer.isReady());
	}
	
	public void testgetBuyingAgentIDs() throws RemoteException {
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		BuyingAgent AgentOne = new BuyingAgent(1);
		TestPlayer.addBuyingAgent(AgentOne);
		assertNotNull(TestPlayer.getBuyingAgentIDs());	
		assertFalse(TestPlayer.usedAllBuyingAgents());
		TestPlayer.removeBuyingAgent(1);
		assertTrue(TestPlayer.usedAllBuyingAgents());
	}
	
	public void testgetInventoryIDs() throws RemoteException {
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		TowerElement myTower = new TowerElement(1);
		TestPlayer.addElementToInventory(myTower);
		TowerElement myGoldenTower = new TowerElement(3);
		TestPlayer.addElementToInventory(myGoldenTower);
		int[] TowerInventory = new int[2];
		TowerInventory[0] = 1;
		TowerInventory[1] = 3;
		assertArrayEquals(TowerInventory,TestPlayer.getInventoryIDs());
	}
	
	public void testendOfSeason() throws RemoteException {
		myBoard = new GameBoard();
		TestPlayer = new Player(myBoard);
		TowerElement myTowerElement = new TowerElement(1);
		TestPlayer.addElementToInventory(myTowerElement);
		TowerElement myGoldenTowerElement = new TowerElement(3);
		TestPlayer.addElementToInventory(myGoldenTowerElement);
		assertEquals(0, TestPlayer.getPoints());
		Tower myTower = new Tower();
		myTower.assemble("3,84");
		TestPlayer.getTowers().add(myTower);
		TestPlayer.endOfSeason();
		assertEquals(2,TestPlayer.getPoints());
	}
}
